import React from 'react'
import List from '../components/List'
import { Provider } from 'mobx-react'
import { initStore } from '../store'

export default class PicPage extends React.Component {
  static async getInitialProps (req) {
    const isServer = !!req
    const store = initStore(isServer)
    const res = await fetch('https://api.imjad.cn/pixiv/v1/?type=rank&id=0&content=illust&mode=monthly&per_page=20&page=1')
    const json = await res.json()

    let item = []
    json.response.forEach(element => {
      item.push(element)
    })
    
    return { list: json.response[0].works, isServer }
  }

  constructor (props) {
    super(props)

    this.store = initStore(props.isServer, props.list)
  }

  render () {
    console.log(this.props)
    return (
      <Provider store={this.store}>
        <List title="图片" apiUrl="https://api.imjad.cn/pixiv/v1/?type=rank&id=0&content=illust&mode=monthly&per_page=20&page="></List>
      </Provider>
    )
  }
}
